package com.v512.guestbook;

public class StringUtil {
	/**
	 * 验证字符串是否为空
	 * 
	 * @param args
	 * @return
	 */
	public static boolean validateNull(String args) {
		if (args == null || args.length() == 0) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * 判断字符串是否为空，为空返回target，不为空返回source
	 * 
	 * @param source
	 * @param target
	 * @return
	 */
	public static String chanageNull(String source, String target) {
		if (source == null || source.length() == 0 || source.equalsIgnoreCase("null")) {
			return target;
		} else {
			return source;
		}
	}

	/**
	 * 对字符串进行过滤，将字符串中的html代码转变成非html代码
	 * 
	 * @param input
	 * @return
	 */
	public static String filterHtml(String input) {
		if (input == null) {
			return null;
		}
		if (input.length() == 0) {
			return input;
		}
		input = input.replaceAll("&", "&amp;");
		input = input.replaceAll("<", "&lt;");
		input = input.replaceAll(">", "&gt;");
		input = input.replaceAll(" ", "&nbsp;");
		input = input.replaceAll("'", "&#39;");
		input = input.replaceAll("\"", "&quot;");
		input = input.replaceAll("\n", "<br>");
		return input;
	}

}
